using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Xml.Serialization;
using Microsoft.MediaCenter.UI;
using System.IO;

namespace Level65.ClipShow
{
    [Serializable]
    public class ClipShowContent
    {
        public ClipShowContent()
        {
        }

        private string _contentSourceName = "";
        private bool _watchFolders = false;

        [XmlAttribute]
        public string ContentSourceName
        {
            get
            {
                return (_contentSourceName);
            }
            set
            {
                _contentSourceName = value;
            }
        }

        [XmlAttribute]
        public bool WatchFolders
        {
            get
            {
                return (_watchFolders);
            }
            set
            {
                _watchFolders = value;
                if (value == true)
                {
                    FindParentFolders();
                }
            }
        }

        [XmlElement(Type = typeof(string))]
        public ArrayList WatchedFolders = new ArrayList();

        [XmlElement(Type = typeof(MediaMetaData))]
        public ArrayList MediaItems = new ArrayList();

        [XmlElement(Type = typeof(ClipItem))]
        public ArrayList KeywordItems = new ArrayList();

        private void FindParentFolders() 
        {
            // Perform a folder pull
            foreach (MediaMetaData mediaItem in this.MediaItems)
            {
                string mediaItemDir = Path.GetDirectoryName(mediaItem.Url);
                if (!this.WatchedFolders.Contains(mediaItemDir))
                {
                    this.WatchedFolders.Add(mediaItemDir);
                }

            }
        }
    }

    [Serializable]
    public class SnagItem
    {
        private string _Name = "";
        private string _snagTimeSpan;
        private MediaClipLengths _clipLength;
        private string _thumbNailUrl;

        [XmlAttribute]
        public string ItemTimeSpan
        {
            get
            {
                return (_snagTimeSpan);
            }
            set
            {
                _snagTimeSpan = value;
            }
        }

        [XmlAttribute]
        public string ThumbnailUrl
        {
            get
            {
                return (_thumbNailUrl);
            }
            set
            {
                _thumbNailUrl = value;
            }
        }

        [XmlAttribute]
        public MediaClipLengths ClipLength
        {
            get
            {
                return (_clipLength);
            }
            set
            {
                _clipLength = value;
            }
        }

        [XmlAttribute]
        public string SnagName
        {
            get
            {
                return (_Name);
            }
            set
            {
                _Name = value;
            }
        }
    }

    [Serializable]
    public class TimelineMetaData
    {
        private int _mediaYear = 2008;
        private int _mediaMonth = 1;

        [XmlElement(Type = typeof(MediaMetaData))]
        public ArrayList TimelineMediaItems = new ArrayList();

        [XmlAttribute]
        public int MediaYear
        {
            get { return (_mediaYear); }
            set { _mediaYear = value; }
        }

        [XmlAttribute]
        public int MediaMonth
        {
            get { return (_mediaMonth); }
            set { _mediaMonth = value; }
        }
    }

    [Serializable]
    public class MediaMetaData
    {
        private string _sourceTitle;
        private string _sourceAuthor;
        private string _sourceDescription;
        private string _sourceUrl;
        private Image _thumbnail;
        private string _thumbnailUrl;
        private Int32 _sourceDuration;
        private DateTime _sourceDateTime;
        private string _snagTimeSpan;
        private MediaClipLengths _snagClipLength;
        private bool _isSnagItem = false;
        private string _parent;


        [XmlIgnore]
        public string Parent
        {
            get { return (_parent); }
            set { _parent = value; }
        }

        [XmlIgnore]
        public bool IsSnagItem
        {
            get
            {
                return (_isSnagItem);
            }
            set
            {
                _isSnagItem = value;
            }
        }

        [XmlIgnore]
        public string SnagTimeSpan
        {
            get
            {
                return (_snagTimeSpan);
            }
            set
            {
                _snagTimeSpan = value;
            }
        }

        [XmlIgnore]
        public MediaClipLengths SnagClipLength
        {
            get
            {
                return (_snagClipLength);
            }
            set
            {
                _snagClipLength = value;
            }
        }

        [XmlElement(Type = typeof(SnagItem))]
        public ArrayList SnagList = new ArrayList();

        [XmlAttribute]
        public Int32 Duration
        {
            get { return (_sourceDuration); }
            set { _sourceDuration = value; }
        }

        [XmlAttribute]
        public DateTime CreationDateTime
        {
            get { return (_sourceDateTime); }
            set { _sourceDateTime = value; }
        }

        [XmlAttribute]
        public string Url
        {
            get { return (_sourceUrl); }
            set { _sourceUrl = value; }
        }

        [XmlAttribute]
        public string Author
        {
            get { return (_sourceAuthor); }
            set { _sourceAuthor = value; }
        }

        [XmlAttribute]
        public string Description
        {
            get { return (_sourceDescription); }
            set { _sourceDescription = value; }
        }

        [XmlAttribute]
        public string Title
        {
            get { return (_sourceTitle); }
            set { _sourceTitle = value; }
        }

        [XmlIgnore]
        public Image Thumbnail
        {
            get { return (_thumbnail); }
            set { _thumbnail = value; }
        }

        [XmlAttribute]
        public string ThumbnailUrl
        {
            get { return (_thumbnailUrl); }
            set { _thumbnailUrl = value; }
        }

        public MediaMetaData Clone()
        {
            return ((MediaMetaData)this.MemberwiseClone());
        }
    }
}
